import { Action, getModule, Module, Mutation, VuexModule } from 'vuex-module-decorators';

import { store } from '@/store';
import { messReadyCount } from '@/api/message';

export interface IMessageState {
  readCount: number;
}

@Module({ dynamic: true, namespaced: true, store, name: 'message' })
class Message extends VuexModule implements IMessageState {
  readCount = 0;

  @Mutation
  setReadCount(readCount: number): void {
    this.readCount = readCount;
  }

  @Action
  async messageInfo() {
    messReadyCount().then(res => {
      const { data } = res;
      this.readCount = data.data.unReadNum;
    });
  }
}

export const messageStore = getModule<Message>(Message);
